<?php
/**
 * Created by PhpStorm.
 * User: 程阳
 * Date: 2018/4/1
 * Time: 11:35
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\service\WxNotify;
use app\api\validate\IDMustBePositiveInt;
use app\api\service\Pay as PayService;

class Pay extends BaseController
{
    protected $beforeActionList = [
        'checkExclusiveScope' => ['only' => 'getPreOrder']
    ];
    
    /**
     * 调用微信支付接口生成预订单
     * @url /pay/pre_order POST
     * @param string $id 订单id
     * @return array|bool
     */
    public function getPreOrder($id = ''){
        (new IDMustBePositiveInt())->goCheck();
        $pay = new PayService($id);
        // 支付生成预订单，这里省略这一步，默认返回成功
        return $pay->pay();
    }
    
    /**
     * 模拟微信支付回调接口
     * @param $data
     * @return bool
     */
    public function redirectNotify($data){
        $notify = new WxNotify();
        return $notify->NotifyProcess($data);
    }
}